using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Web;



namespace HYBY.WebFrameWork.Mvc {

    public class UploadServerConfiguration:ConfigurationSection {        


        [ConfigurationProperty("ImageServers", IsDefaultCollection = true, IsRequired = true)]
        public ServerList ImageServers {
            get {
                return (ServerList)base["ImageServers"];
            }
        }

        [ConfigurationProperty("FileServers", IsDefaultCollection = true,IsRequired=false)]
        public ServerList FileServers {
            get {
                return (ServerList)base["FileServers"];
            }
        }

        [ConfigurationProperty("VideoServers", IsDefaultCollection = true,IsRequired = false)]
        public ServerList VideoServers {
            get {
                return (ServerList)base["VideoServers"];
            }
        }
    }

    public class ServerList : ConfigurationElementCollection {

        protected override ConfigurationElement CreateNewElement() {
            return new ServerDescriptor();
        }

        protected override object GetElementKey(ConfigurationElement element) {
            return ((ServerDescriptor)element).ServerURL;
        }

        public override ConfigurationElementCollectionType CollectionType {
            get {
                return ConfigurationElementCollectionType.BasicMap;
            }
        }

        protected override string ElementName {
            get {
                return "Server";
            }
        }

        [ConfigurationProperty("UploadPath", IsRequired = true, DefaultValue = "Upload")]
        public String UploadPath {
            get {
                return (String)base["UploadPath"];
            }
            set {
                base["UploadPath"] = value;
            }
        }

        public ServerDescriptor this[int index] {
            get {
                return (ServerDescriptor)BaseGet(index);
            }
            set {
                if (BaseGet(index) != null) {
                    BaseRemoveAt(index);
                }
                BaseAdd(index, value);
            }
        }
    }

    public class ServerDescriptor : ConfigurationElement {

        [ConfigurationProperty("ServerID", IsRequired = false)]
        public String ServerID {
            get {
                return (String)base["ServerID"];
            }
            set {
                base["ServerID"] = value;
            }
        }

        [ConfigurationProperty("ServerName", IsRequired = false)]
        public String ServerName {
            get {
                return (String)base["ServerName"];
            }
            set {
                base["ServerName"] = value;
            }
        }

        [ConfigurationProperty("ServerURL", IsRequired = true)]
        public String ServerURL {
            get {
                return (String)base["ServerURL"];
            }
            set {
                base["ServerURL"] = value;
            }
        }

        [ConfigurationProperty("ServerDescrption", IsRequired = false)]
        public String ServerDescrption {
            get {
                return (String)base["ServerDescrption"];
            }
            set {
                base["ServerDescrption"] = value;
            }
        }

    }
 
 
}